import { BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import * as apis from '/@/api/iam/dept';
import { AvailableEnum } from '/@/enums';
import { render } from "/@/utils/common/renderUtils"

const { t } = useI18n('');

export const columns: BasicColumn[] = [
  {
    title: t('部门名称'),
    dataIndex: 'deptName',
    width: 170,
    align: 'left',
    slot: 'firstColumn',
  },
  {
    title: t('排序编号'),
    dataIndex: 'sortNo',
    width: 100,
  },
  {
    title: t('负责人'),
    dataIndex: 'leader',
    width: 100,
  },
  {
    title: t('更新者'),
    dataIndex: 'updatedBy',
    width: 120,
  },
  {
    title: t('更新时间'),
    dataIndex: 'updatedAt',
    width: 160,
    align: 'center',
  },
  {
    title: t('状态'),
    dataIndex: 'status',
    width: 100,
    customRender: ({ text }) => {
      const color = text == AvailableEnum.NORMAL ? "green" : "red"
      return render.renderTag(text == AvailableEnum.NORMAL ? "正常" : "停用", color)
    },
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('部门名称'),
    field: 'deptName',
    component: 'Input',
  },
  {
    label: t('部门标识'),
    field: 'deptCode',
    component: 'Input',
  },
  {
    label: t('部门状态'),
    field: 'status',
    component: "JDictSelectTag",
    componentProps: {
      allowClear: true,
      dictType: "DataAvailable",
      placeholder: "全部",
      stringToNumber: true,
    },
  },
];



export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('部门名称'),
    required: true,
    field: 'deptName',
    component: 'Input',
    componentProps: {
      maxlength: 128,
    },
  },
  {
    label: t('排序编号'),
    required: true,
    field: 'sortNo',
    defaultValue: 1,
    component: 'InputNumber'
  },
  {
    label: t('父级'),
    required: false,
    field: 'parentId',
    component: "MyTreeSelect",
    componentProps: {
      immediate: true,
      api: () => apis.listDeptTree({  }),
      placeholder: "根节点",
      fieldNames: {
        label: "deptName",
        pid: "parentId",
        key: "id",
        value: "id",
      },
    },

  },
  {
    label: t('负责人'),
    required: true,
    field: 'leader',
    component: 'Input',
    componentProps: {
      maxlength: 128,
    },

  },
  {
    label: t('联系电话'),
    required: false,
    field: 'phone',
    component: 'Input',
    componentProps: {
      maxlength: 20,
    },

  },
  {
    label: t('邮箱'),
    required: false,
    field: 'email',
    component: 'Input',
    componentProps: {
      maxlength: 20,
    },

  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
    },
    colProps: { lg: 24, md: 24 },
  },
];
